<?php

namespace App\Recharge\Api;

use App\Models\InterfaceConfiguration;
use App\Recharge\Bean\ApiNotifyDataBean;
use App\Recharge\Bean\BasicInformation;
use Illuminate\Http\Request;

class Miaoyinyue extends AbstractApi
{
    /**
     * @inheritDoc
     */
    public function rechargeData(BasicInformation $bean): array
    {
        $array = [
            'agent_account'=>(string)$bean->getSupplierNum(),//商户号
            'order_no' => (string)$bean->getOrderNo(),//订单号
            'gid' => (string)$bean->getGoodsId(),
            'recharge_num' => (string)$bean->getRechargeNum() * $bean->getStartCharging() ,//充值数量,
            'recharge_account' => (string)$bean->getAccount(),
            'notify_url' => $bean->getNotifyUrl(),
        ];
        ksort($array);
        $array['sign'] = md5(json_encode($array));
        return $array;
    }
    /**
     * @param InterfaceConfiguration $api
     * @param Request $request
     * @return ApiNotifyDataBean
     */
    public function apiNotifyLogic(InterfaceConfiguration $api, Request $request): ApiNotifyDataBean
    {
        $status = $request->input('status', '');
        $order_sn = $request->input('rechargeData', '');
        return $this->apiNotifyData($order_sn['order_no'], $status)->setExecute(in_array($status, [1, 2]))->setRechargeSuccess($status ==1);
    }
}
